<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>使用函数实现模块化</title>
</head>
<body>

<div>
    <button onclick="add()">add</button>
    <br>
    <button onclick="list()">list</button>
</div>
<script type="application/javascript">
    function collection(){

        let arr = [1,2,3];
        function add(num){
            arr.push(num)
        }
        function list(){
            arr.forEach(a=>{
                console.log(a)
            })
        }
        return {add,list}
    }
    let obj = collection()
    let count = 4;
    function add(){
        obj.add(count++)
    }

    function list(){
        obj.list()
    }

    add.apply(add)


</script>
</body>
</html>
